package fem2.observer;

import java.io.IOException;

import fem2.Model;
import fem2.level_set.LevelSet;

public class GidLevelSetObserver extends GidStructuralObserver {

	private LevelSet ls;

	public GidLevelSetObserver(Model m, LevelSet ls, TimeStepObserver o, String projectDir,
			String projectName) {
		super(m, o, projectDir, projectName);
		this.ls = ls;
	}

	public GidLevelSetObserver(Model m, LevelSet ls, TimeStepObserver o, String projectDir,
			String projectName, String fileName) {
		super(m, o, projectDir, projectName, fileName);
		this.ls = ls;
	}

	@Override
	public void fireStarted() {
	}

	@Override
	public void fireTimeStepStarted() {
	}

	@Override
	public void fireIterationStarted() {
	}

	@Override
	public void fireIterationFinished() {
	}

	@Override
	public void fireTimeStepFinished() {
		/*
		 * output to file as needed
		 */
		if (gidPost != null) {
			double timeStep = timeStepObserver.getCurrentTimeStep();

			try {
				gidPost.writeMesh(m, timeStep);
				gidPost.writeNodalLevelSetValues(m, ls, timeStep);
			} catch (IOException e) {
				throw new Error("Write failed: " + e.getMessage());
			}
		}
	}

	@Override
	public void fireFinished() {
	}

}
